<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>

        <ui:composition template="../templates/default3.xhtml">  

            <ui:define name="content">

                <h:form id="quotationPage" binding="#{quotationManagerBean.loadQuotationPage}">

                    <p:panel header="Quotation Information" id="quotationInformationPanel">
                        <font class="fieldNote">* - Mandatory Field<br/></font>
                        <p:messages />
                        <table width="100%">
                            <tr>
                                <td width="150px">
                                    Status:
                                </td>
                                <td>
                                    <h:outputText id="status" value="#{userSessionManagerBean.selectedQuotation.status}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="150px">
                                    Remarks:
                                </td>
                                <td>                                
                                    <table>
                                        <tr>
                                            <td><h:inputTextarea required="true" requiredMessage="Remarks Required" 
                                                                 id="remark" value="#{quotationManagerBean.remark}"
                                                                 style="width:450px;height:75px;" title="Remarks for the quotation.">
                                                </h:inputTextarea></td>
                                            <td><font class="fieldNote">*</font></td>
                                        </tr>
                                    </table></td>
                            </tr>
                        </table>
                    </p:panel>

                    <p:panel header="Add Quotation Item" id="addQuotationItemPanel">
                        <table width="100%">
                            <tr>
                                <td width="150px">Product:</td>
                                <td>
                                    <h:selectOneMenu id="selectOneProduct" value="#{quotationManagerBean.product.code}"
                                                     title="Product to be quoted.">
                                        <f:selectItem itemLabel="Select Product" itemValue="" />
                                        <f:selectItems value="#{quotationManagerBean.products}" var="product" 
                                                       itemLabel="#{product.name}" itemValue="#{product.code}"/>
                                    </h:selectOneMenu>
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            
                               <tr>
                                        <td width="150px">Request Date </td>
                                            <td>
                                                <p:calendar mindate="#{quotationManagerBean.minDate}" required="true" requiredMessage="Request Date Required" 
                                                            value="#{quotationManagerBean.requestDate}" pattern="dd-MM-yyyy" 
                                                            title="Date of delivery."/> 
                                                <font class="fieldNote">*</font>
                                            </td>
                          
                                    </tr>

                                    <tr>
                                        <td width="150px">Quantity:</td>
                                        <td><p:inputText id="quantity" value="#{quotationManagerBean.quantity}" required="true"
                                                         requiredMessage="Quantity Required" label="Quantity"
                                                         title="Number of bars. To be divided into cases of 240 for shipping.">                          
                                            </p:inputText>
                                            <font class="fieldNote">*</font>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="150px">Discount (%):</td>
                                        <td><p:inputText id="discount" value="#{quotationManagerBean.discount}" required="true"
                                                         requiredMessage="Discount Required" label="Discount"
                                                         title="Discount given to total costs involved excluding shipping. For e.g., a value of 10 entered means 10% discount.">
                                                <f:convertNumber minFractionDigits="2" />     
                                            </p:inputText>
                                            <font class="fieldNote">*</font>
                                            <br/>
                                            <p:commandLink onclick="discount.show();" > <font size ="1" color="blue" > Discount schemes  </font> </p:commandLink> 

                                            <p:dialog id="discounts" header="Discount schemes"  widgetVar="discount" height="180" resizable="false"  >  

                                                <table border="1" >
                                                    <tr>
                                                        <td width="200px" align="center" > <b>Bar</b></td> 
                                                        <td align="center" ><b>Quantity</b></td> 
                                                    </tr>
                                                    <tr>
                                                        <td align="center" >1 to 2399</td> 
                                                        <td align="center" >0%</td> 
                                                    </tr>
                                                    <tr>
                                                        <td align="center"  >2400 to 11999</td> 
                                                        <td align="center" >1%</td> 
                                                    </tr>
                                                    <tr>
                                                        <td align="center" >12000 to 23999</td> 
                                                        <td align="center" >3%</td> 
                                                    </tr>
                                                    <tr>
                                                        <td align="center"  > > 23999</td> 
                                                        <td align="center" >5%</td> 
                                                    </tr>
                                                </table>


                                            </p:dialog>    

                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="120px">Shipping Location:</td>
                                        <td>
                                            <p:dataTable id="shippingAddresses" var="address" value="#{quotationManagerBean.shippingAddresses}" paginator="false" 
                                                         selectionMode="single" selection="#{quotationManagerBean.shippingAddress}"
                                                         emptyMessage="No address found with given criteria.">                               
                                                <p:column headerText="Street"> 
                                                    <h:outputText value="#{address.street}" />                                             
                                                </p:column> 
                                                <p:column headerText="Postal Code"> 
                                                    <h:outputText value="#{address.postal}" />                                             
                                                </p:column> 
                                                <p:column headerText="City"> 
                                                    <h:outputText value="#{address.city}" />                                             
                                                </p:column> 
                                                <p:column headerText="Country"> 
                                                    <h:outputText value="#{address.country}" />                                             
                                                </p:column> 
                                            </p:dataTable>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="150px">Shipping Method:</td>
                                        <td>
                                            <h:selectOneMenu id="selectOneShippingMethod" value="#{quotationManagerBean.shippingMethod}"
                                                             title="Shipping method to be used. Different shipping method varies in shipping costs.">
                                                <f:selectItem itemLabel="Select Method" itemValue="" />
                                                <f:selectItem itemLabel="Free On Board" itemValue="FOB" />
                                                <f:selectItem itemLabel="Cost and Freight" itemValue="CFR" />
                                            </h:selectOneMenu>
                                            <font class="fieldNote">*</font>
                                        </td>
                                    </tr>


                                    <tr>
                                        <td colspan="2" class="btn"><hr/>
                                            <p:commandButton value="Add Quotation Item" ajax="true"
                                                             actionListener="#{quotationManagerBean.addQuotationItem}" 
                                                             update="quotationPage"
                                                             disabled="#{quotationManagerBean.isExpiredQuotation}"
                                                             title="Add the item to be quoted. Expired quotations cannot be updated."/>
                                        </td>
                                    </tr>
                                    </table>
                                    </p:panel>
                                    <p:panel header="Quotation Items" id="quotationItemsPanel">
                                        <table width="100%">
                                            <tr>
                                                <td align="left">
                                                    <h:outputText id="output" value="Quotation #{userSessionManagerBean.selectedQuotation.id} 
                                                                  has #{quotationManagerBean.quotationItemsCount} quotation item(s)." />
                                                </td>
                                                <td align="right">

                                                </td>
                                            </tr>
                                        </table>
                                        <hr />
                                        <p:dataTable id="quotationItems" var="quotationItem" value="#{quotationManagerBean.quotationItems}" paginator="false" 
                                                     selectionMode="single" selection="#{quotationManagerBean.quotationItem}"
                                                     emptyMessage="No quotation items found with given criteria.">
                                            <p:column headerText="Name">  
                                                <h:outputText value="#{quotationItem.product.name}" />  
                                            </p:column> 
                                            <p:column headerText="Unit Price">
                                                <h:outputText value="#{quotationItem.unitPrice}">
                                                    <f:convertNumber type="currency"/>
                                                </h:outputText>
                                            </p:column>
                                            <p:column headerText="Quantity">
                                                <h:outputText value="#{quotationItem.quantity}" />
                                            </p:column>
                                            <p:column headerText="Discount">
                                                <h:outputText value="#{quotationItem.discount}" />
                                            </p:column>
                                            <p:column headerText="Request Date">
                                                <h:outputText value="#{quotationItem.requestDate}">
                                                    <f:convertDateTime pattern="dd-MM-yyyy" timeZone="#{defaultManagerBean.tz}"/>
                                                </h:outputText>
                                            </p:column>
                                            <p:column headerText="Shipping Address">
                                                <h:outputText value="#{quotationItem.shippingAddress.street}, #{quotationItem.shippingAddress.city}" />
                                            </p:column>
                                            <p:column headerText="Shipping Rate">
                                                <h:outputText value="#{quotationItem.shippingRate}">
                                                    <f:convertNumber type="currency"/>
                                                </h:outputText>
                                            </p:column>
                                            <p:column headerText="Subtotal">
                                                <h:outputText value="#{quotationItem.subTotal}">
                                                    <f:convertNumber type="currency"/>
                                                </h:outputText>
                                            </p:column>
                                        </p:dataTable>
                                        <p:commandButton value="Delete Selected" actionListener="#{quotationManagerBean.delete}" ajax="true" 
                                                         id="btnDeleteQuotationItem" update="quotationPage"
                                                         title="Delete selected quotation item."
                                                         disabled="#{quotationManagerBean.isExpiredQuotation}"/>
                                        <br/>
                                        <br/>
                                        <font size="1">
                                            <h:commandLink id="CustomerQuotation" actionListener="#{reportManagerBean.getReports}"
                                                           title="View quotation report."
                                                           disabled="#{quotationManagerBean.isAddJob or quotationManagerBean.isEmptyQuotation}">
                                                <h:outputText value="+ Quotation"/>
                                            </h:commandLink>
                                        </font>

                                        <hr />
                                        <center>
                                            <p:commandButton value="Back" ajax="true" actionListener="#{quotationManagerBean.back}" 
                                                             update="quotationPage" title="Go back to previous page."
                                                             disabled="#{quotationManagerBean.isEmptyQuotation}"/>
                                            <p:commandButton value="Save Quotation" ajax="true" actionListener="#{quotationManagerBean.saveQuotation}" 
                                                             update="quotationPage" title="Save the quotation."
                                                             disabled="#{quotationManagerBean.isExpiredQuotation}"/>
                                        </center>
                                    </p:panel>
                                    </h:form>
                                    </ui:define>
                                    </ui:composition>
                                    </body>
                                    </html>
